package com.yejiali.backend.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.yejiali.backend.entity.ResultMessage;

import java.util.Date;

/**
 * @Author:yejiali
 * @Date:2025/8/19-08-19-11:27
 * @Decsription:com.yejiali.backend.util
 * @Version:1.0
 */
public class MessageUtil {
    public static <T> String getMessage(String type,String fromUserId,T message) throws JsonProcessingException {
        ResultMessage<T> resultMessage = new ResultMessage<>();
        resultMessage.setType(type);
        if(fromUserId!=null){
            resultMessage.setFromUserId(fromUserId);
        }
        resultMessage.setMessage(message);
        resultMessage.setTimestamp(new Date());
        return JsonUtil.toJson(resultMessage);
    }
}
